package com.yh.csx.event.store.gateway.backup;

import com.yh.csx.event.store.gateway.backup.dataobject.BizEventResultBakDo;
import com.yh.csx.event.store.gateway.event.dataobject.BizEventDo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;

@Repository
public interface EventResultBakRepository extends JpaRepository<BizEventResultBakDo, String> {

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "insert ignore into biz_event_result_temp select * from biz_event_result a  where  a.status=402 and a.create_time <= :createTime limit 100 ")
    void move2Temp(@Param("createTime") String createTime);

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "insert ignore into biz_event_result_bak select * from biz_event_result_temp")
    void move2Bak();

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "delete from biz_event_result where id in ( select id from biz_event_result_temp )")
    void delResult();

    @Modifying
    @Transactional
    @Query(nativeQuery = true, value = "delete from biz_event_result_temp")
    void delTemp();
}
